package com.baizhi.shane.config;

import com.baizhi.shane.common.base.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 由衷感谢
 * https://blog.csdn.net/ying456baby/article/details/121291964
 */
@ControllerAdvice
public class ExceptionAdvice {
    public static Logger logger = LoggerFactory.getLogger(ExceptionAdvice.class);

 
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Result<?> handleException(RuntimeException e) {
        e.printStackTrace();
        logger.error("异常信息：", e.getMessage());
        Result result = Result.fail(500, e.getMessage()); // 之前是500

        return result;
    }
 

 
}